package com.sudoku.input;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.sudoku.screen.GameScreen;
import com.sudoku.screen.MenuScreen;
import com.sudoku.utility.Constants;
import com.sudoku.utility.Locator;

public class InputHandler implements InputProcessor, Constants {
	private GameScreen screen;

	public InputHandler(GameScreen screen) {
		this.screen = screen;
	}

	@Override
	public boolean keyDown(int keycode) {
		switch (keycode) {
		case Keys.U:
			screen.undo();
			break;
		case Keys.BACK:
			if (Locator.getGame().getScreen() instanceof MenuScreen) {
				Gdx.app.exit();
			} else if (Locator.getGame().getScreen() instanceof GameScreen) {
				Gdx.input.setCatchBackKey(false);
				screen.gotoMenu();
			}

			break;
		default:

		}
		return false;
	}

	@Override
	public boolean keyUp(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyTyped(char character) {
		if ((character > 47 && character < 58) || character == ' ' || character == '?') {
			screen.setTileData(character);
		}
		return false;
	}

	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		screen.findTile(screenX, screenY);
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		screen.selectTile(screenX, screenY);
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		screen.findTile(screenX, screenY);
		return false;
	}

	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean scrolled(int amount) {
		// TODO Auto-generated method stub
		return false;
	}

}